<template>
	<view>
		
		
		
		<view class="mode">
			<u-form :model="form" ref="uForm">
				<u-form-item :label="status==1?'微信':'支付宝'" label-width="150" prop="name" :border-bottom="false">
					<u-input v-model="form.name" placeholder="请输入您的真实姓名" />
				</u-form-item>
			</u-form>
		</view>


		<view class="mode">

			<u-cell-item title="收款码上传" value="请上传您的收款二维码" :border-bottom="false" :arrow="false"></u-cell-item>
			<upload_img ref="videoUpload" type="image" @uploaded="uploaded" :afterLoadUrl="form.image_url" defaultLength="1"></upload_img>
		</view>


		<u-button shape="circle"
			:custom-style="{background:'#628DFF',color:'#fff',marginTop:'40rpx',width:'500rpx',marginBottom:'40rpx'}"
			@click="submit">
			保存并使用</u-button>
    
							      <u-toast ref="uToast" />
	</view>
</template>

<script>
	import upload_img from '../../components/upload_img.vue';
	export default {
		components: {
			upload_img
		},
		data() {
			return {
				label: "支付宝账号",
				status:"",
				form: {
					
					name: '',

				},
				rules: {
					name: [{
						required: true,
						message: '请输入您的真实姓名',
						// 可以单个或者同时写两个触发验证方式 
						trigger: ['change', 'blur'],
					}],
				
				}
			}
		},
		methods: {
			submit() {
			
				this.$refs.uForm.validate(valid => {
					if (valid) {
						if(!this.$refs.videoUpload.afterUploadImgList.length){
							uni.$u.toast("请上传收款码")
							
						}else{
							if(this.status==2){
								this.$u.post('/user/saveInfo', {
								 	alipay_qr:this.$refs.videoUpload.afterUploadImgList[0],
									alipay_name:this.form.name
								}, {}).then(res => {
								  
								      this.$refs.uToast.show({
								      		title: '提交成功',
								      		type: 'success',
											back:true
								      })
														 
								}).catch(err => {})
							}else{
								this.$u.post('/user/saveInfo', {
								 	wx_qr:this.$refs.videoUpload.afterUploadImgList[0],
									wx_name:this.form.name
								}, {}).then(res => {
								  
								      this.$refs.uToast.show({
								      		title: '提交成功',
								      		type: 'success',
											back:true
								      })
														 
								}).catch(err => {})
							}
							
						}
		
					} else {
						console.log('验证失败');
					}
				});
			}

		},
		onReady() {
			this.$refs.uForm.setRules(this.rules);
		},
		onLoad(options) {
			if(options.id){
				this.status=options.id
			}
		}
	}
</script>

<style lang="scss">
	
</style>
